<?php

//参加测评的视图模型

function project_model($sort,$sortrule,$groupuser,$groupid,$groupname){
	//设置标题宽度
	$sortlength=2*count($sort);
	foreach ($sort as $key => $value) {
		$sorttype=getdataf('sorttype','app_sort','sortid',$key);
		if ($sorttype==2) {
			$sortson='';
			$sortsonid=getdataallfc('sortid','app_sort','sortupid',$key);
			$sortlength+=count($sortsonid)-1;
		}
	}
	//echo $sortlength;
?>
<div class="model">
	<form action="user.app.php" method="post" >
		<input type="hidden" name="system_groupid" value=<?php echo "'".$groupid."'" ?>/>
		<input type="hidden" name="sort_type" value=<?php echo "'".$sortrule['type']."'" ?>/>
		<div class="model_table">
	<table>
		<tr>
			<td colspan=<?php echo "'".$sortlength."'"; ?>><?php echo $groupname;?></td><td style="width:30%;">备注</td>
		</tr>
		<tr>
			<td style="min-width:120px;">用户名</td>
			<?php
			foreach ($sort as $key => $value) {
				$sorttype=getdataf('sorttype','app_sort','sortid',$key);
				$thislength=1;
				if ($sorttype==2) {
					$sortson='';
					$sortsonid=getdataallfc('sortid','app_sort','sortupid',$key);
					$thislength=count($sortsonid);
				}
				echo "<td colspan='".$thislength."'>";
				echo $value;
				echo "</td>";
				echo "<td id='tdline'></td>";
			}
			if($sortlength>2*count($sort)){
				echo "<tr>";
				echo "<td>/</td>";
				foreach ($sort as $key => $value) {
					$sorttype=getdataf('sorttype','app_sort','sortid',$key);
					if ($sorttype==2) {
					$sortson='';
					$sortsonid=getdataallfc('sortid','app_sort','sortupid',$key);
					foreach ($sortsonid as $key => $value) {
						echo "<td>".getdataf('sortname','app_sort','sortid',$value)."</td>";
					}
				
					}
					echo "<td id='tdline'></td>";
				}

				echo "</tr>";
			}
			
			?>
		</tr>
	<?php
		foreach ($groupuser as $key => $value) {
			display_user($key,$value,$sort,$groupid);
		}
	?>
	</table>
	</div>
	<div class="model_submit">
		<input class="ubutton" type="submit" value="提交" />
		<input class="ubutton" type="reset" value="重置" />
	</div>
	</form>
</div>
<?php
}


//一个$userid被评论$sort的模型
function display_user($userid,$username,$sort,$groupid){
	echo "<tr>";
	echo "<td>".$username."</td>";
	foreach ($sort as $key => $value) {
		$sorttype=getdataf('sorttype','app_sort','sortid',$key);
		//如果是等级选择
		if($sorttype==2){
			//获取子项目
			$sortson='';
			$sortsonid=getdataallfc('sortid','app_sort','sortupid',$key);
			foreach ($sortsonid as $tkey => $tvalue) {
				$sortson[$tvalue]['sortname']=getdataf('sortname','app_sort','sortid',$tvalue);
				$sortson[$tvalue]['sortpoint']=getdataf('sortpoint','app_sort','sortid',$tvalue);
				$sortson[$tvalue]['sortmax']=getdataf('sortmax','app_sort','sortid',$tvalue);
			}

			//获取允许最多的项目
			$maxsort=0;
			$maxsortid="";
			foreach ($sortson as $tkey => $tvalue) {
				if($tvalue['sortmax']>$maxsort){
					$maxsortid=$tkey;
					$maxsort=$tvalue['sortmax'];
				}
			}
			
			//显示子项目
			foreach ($sortson as $tkey => $tvalue) {
				//设置默认选项
				$checked="";
				$checked2="background-color:#fff;";
				if($maxsortid==$tkey){
					$checked="checked";
					$checked2="background-color:yellow;";

				}
				$inputname=$key."_".$userid."_".$groupid;
				$inputid=$tkey."_".$userid."_".$groupid;
				echo "<td>
						<input class='modelradio' ".$checked." type='radio' id='".$inputid."' name='".$inputname."' value='".$tvalue['sortpoint']."' />
						<label for='".$inputid."'><div style='width:22px;height:22px;border-radius: 11px;".$checked2."' id='td_".$inputname."' onclick='changechoose(this)'></div></label>
					</td>";
				//"";
			}
		}
		//如果是填写分数
		else if($sorttype==1){
			echo "<td><input pattern=\"0|[0-9]|[0-9][0-9]|100\" required type='text' name='".$key."_".$userid."' /></td>";
		}
		echo "<td id='tdline'></td>";
	}
	echo "</tr>";
}
?>